package app.fugema.shop.main.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.base.common.utils.DensityUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.widget.banner.BannerImageLoader;
import com.base.common.view.widget.imageView.GlideImageView;
import com.base.common.view.widget.imageView.ImageLoaderUtils;
import com.base.common.view.widget.imageView.ShapeType;
import app.fugema.shop.R;
import app.fugema.shop.databinding.HomeBannerBinding;
import app.fugema.shop.main.goods.view.GoodsDetailActivity;
import app.fugema.shop.main.home.model.BannerData;
import app.fugema.shop.main.home.model.HomeData;

import com.jeremyliao.liveeventbus.LiveEventBus;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;
import com.zhpan.bannerview.constants.PageStyle;


public class HomeBannerItemType extends BaseItemMultiType<BannerData, HomeBannerBinding>
{
    //首页banner
    @Override
    public int getLayoutId()
    {
        return R.layout.home_banner;
    }

    @Override
    public int getItemViewType()
    {
        return TYPE_HEAD;
    }

    @Override
    public boolean isFullSpanType() {
        return true;
    }

    @Override
    public void onCreateViewHolder(HomeBannerBinding binding, BaseViewHolder viewHolder)
    {
        super.onCreateViewHolder(binding, viewHolder);
        // 替换banner 库
        /*
        binding.banner.setIndicatorGravity(BannerConfig.CENTER);
        LinearLayout circleIndicator = binding.banner.findViewById(R.id.circleIndicator);
        if (circleIndicator != null) {
            circleIndicator.setPadding(DensityUtil.getDimens(R.dimen.dp_32), 0, 0, DensityUtil.getDimens(R.dimen.dp_10));
        }
        */
    }

    @Override
    public void onBindViewHolder(HomeBannerBinding binding, int position, BannerData bean)
    {
        super.onBindViewHolder(binding, position, bean);

        binding.banner.setHolderCreator(NetBannerProvider::new)
                      .setPageStyle(PageStyle.MULTI_PAGE_OVERLAP)
                      .setIndicatorMargin(DensityUtil.dp2px(10),DensityUtil.dp2px(10),DensityUtil.dp2px(10),DensityUtil.dp2px(15))
                      .setOnPageClickListener(position1 -> {

                          HomeData.DatasetBean bannerData = (HomeData.DatasetBean)binding.banner.getList().get(position1);
                          switch (bannerData.getLinkType())
                          {
                              case 1:
                                  GoodsDetailActivity.start(binding.banner.getContext(),bannerData.getLinkType() );
                                  break;
                          }
                          //处理 banner 数据
                          UIUtils.showToastSafes( bannerData.getShowtitle() );
                      })
                      .create( bean.getData() );
        /*
        binding.banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                HomeData.DatasetBean dataBean = bean.getData().get(position);
                //
                switch (dataBean.getLinkType())
                {
                    case 1:
                        GoodsDetailActivity.start(binding.banner.getContext(), dataBean.getTargetId());
                        break;
                }
            }
        });
        binding.banner.setImages(bean.getData()).setImageLoader(new BannerImageLoader() {
            @Override
            public void displayImage(Context context, Object path, GlideImageView imageView) {
                HomeData.DatasetBean bannerInfo = (HomeData.DatasetBean) path;
                ImageLoaderUtils.loadImage(imageView, bannerInfo.getPic());
            }
            int dp16 = DensityUtil.getDimens(R.dimen.dp_15);
            @Override
            public GlideImageView createImageView(Context context) {
                GlideImageView glideImageView = super.createImageView(context);
                glideImageView.setShapeType(ShapeType.ROUNDRECT);
                glideImageView.setRadius(DensityUtil.getDimens(R.dimen.dp_18));
                glideImageView.setScaleType(ImageView.ScaleType.FIT_XY);
                //dp16
                int padding = DensityUtil.getDimens(R.dimen.dp_10);
                glideImageView.setPadding(padding, padding, padding, padding);
                return glideImageView;
            }
        }).setDelayTime(3000).start();
        */

    }


}
